import 'package:applications/database/local_db.dart';
import 'package:applications/module/home/home_page.dart';
import 'package:applications/utils/provider_logger.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

void main() async {
  runApp(
    ProviderScope(
      observers: [ProviderLogger()],
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  final Widget? home;

  const MyApp({Key? key, this.home}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    LocalDb.instance.initDb();
    return ScreenUtilInit(
      // 设计稿按iPhone6的尺寸设计的(iPhone6 750*1334)
      designSize: const Size(750, 1334),
      // allowFontScaling: false,
      builder: (context, child) => MaterialApp(
        title: '热门App',
        // 右上角显示一个debug的图标
        debugShowCheckedModeBanner: false,
        // showPerformanceOverlay: true, //显示性能标签
        // checkerboardRasterCacheImages: true,
        // showSemanticsDebugger: true, // 显示语义视图
        // checkerboardOffscreenLayers: true, // 检查离屏渲染
        theme: ThemeData(
          primarySwatch: Colors.blue,
          scaffoldBackgroundColor: Colors.white,
        ),
        builder: (context, widget) {
          return MediaQuery(
            /// Setting font does not change with system font size
            data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
            child: widget ?? const SizedBox.shrink(),
          );
        },
        home: home ?? const HomePage(),
      ),
    );
  }
}
